<template>
	<view class="content_view">
		<!-- <topicon class="topicon" :iconWidth="100" :iconHeight="100" :startPostion="3" iconPath="../../../../static/img/zhiding.png"
				 :marginBottom="10" :marginTop="60" :marginLeft="5" :marginRight="10" @tapIcon="tapIcon"
				></topicon> -->
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true"
			:title="'检测任务详情'"></u-navbar>
		<uc-content :loading="loading">
			<view class="list-item">
				<view class="list-bottom">
					<view>任务名称:</view>
					<view>{{examineTaskInfo.task.taskName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>检测人员:</view>
					<view>{{examineTaskInfo.task.executorName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>业主名称:</view>
					<view>{{examineTaskInfo.task.enterpriseName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>检测企业:</view>
					<view>{{examineTaskInfo.task.examineName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>任务状态:</view>
					<view>{{mainFormat(examineTaskInfo.task.examineStatus)}}</view>
				</view>
			</view>
			<view style="width:100%;margin-top: 15px; margin-left: 2.5%;">
				<view style="width:95%;">
					<u-button v-if="examineTaskInfo.task.examineStatus==2 " @click="startExecute()" type="primary"
						shape="square">开始执行</u-button>
					<u-button v-if="examineTaskInfo.task.examineStatus==3 && examineTaskInfo.task.isStop" @click="setStartExamine()" type="primary"
						shape="square">继续执行</u-button>
					<u-button v-if="examineTaskInfo.task.examineStatus==3 && !examineTaskInfo.task.isStop " @click="setStartExamine()" type="primary"
						shape="square">暂停执行</u-button>
					<u-button style="margin-top: 10rpx;" v-if="examineTaskInfo.task.examineStatus==3" @click="completeTask()" type="error"
						shape="square">结束本次检测</u-button>
				</view>
			</view>
			<uni-collapse accordion v-for="(value, key) in examineTaskInfo.tree">
				<uni-collapse-item :title="value.name + '   已完成' + value.doneNum + '项/需要完成' + value.totalNum + '项'"
					class="collapse-title" :open="key === 0?true:false">
					<view class="list-item" v-for="(item, ind) in value.children" :key="ind">
						<view class="list-top">
							<view class="list-left">
								{{ item.name + ' 已完成' + item.doneNum + '项/需要完成' + item.totalNum + '项' }}
							</view>
						</view>
						<u-button v-if="examineTaskInfo.task.examineStatus==3 && !examineTaskInfo.task.isStop" @click="checkItem(item)" type="primary" shape="square"
							style="margin-right: 5px; width: 20%; float: right; height: 30px;line-height: 30px; font-size: 12px;">
							检测</u-button>
					</view>
				</uni-collapse-item>
			</uni-collapse>
			<uni-popup ref="popup" type="center">
				<uni-popup-message style="width: 90%;margin-left: 5%;border-radius: 5px;" type="error"
					:message="tipMessage">
				</uni-popup-message>
			</uni-popup>
		</uc-content>
	</view>
</template>

<script>
	import topicon from '@/components/gwh-backTopIcon/gwh-backTopIcon.vue'
	import {
		mapGetters
	} from 'vuex'
	export default {
		components: {
			topicon
		},
		data() {
			return {
				examineTaskInfo: {},
				vinMaintenanceInfoDataList: [],
				statusOptions: [],
				mainOptions: [],
				ucId: '',
				tipMessage: '',
				num: 0,
				taskId: "",
				loading: false,
				title: ""
			}
		},
		onLoad(e) {
			this.ucId = e.ucId
		},
		onShow() {
			this.initView(this.ucId)
		},
		computed: {
			...mapGetters(["refresh"])
		},
		watch: {
			refresh: function(a, b) {
				this.initView(this.ucId)
			}
		},
		methods: {
			mainFormat(data) {
				return this.selectDictLabel(this.mainOptions, data);
			},
			checkItem(value) {
				uni.navigateTo({
					url: '/pages/testing/testItem?taskId=' + value.taskId + '&code=' + value.code + '&status=' +
						value.status + '&totalNum=' + value.totalNum + '&bind=' + value.bind + '&devType=' + value.devType
				})
			},
			collapseChange(value) {
				this.vinMaintenanceInfoDataList = value.inMaintenanceInfoDataList
			},
			tapIcon(e) {
				//此处为处理方法
				uni.pageScrollTo({
					duration: 60,
					scrollTop: 0
				})
			},
			statusFormat(data) {
				return this.selectDictLabel(this.statusOptions, data);
			},
			initView(val) {
				this.loading = true
				this.examineTaskInfo = {}
				this.pageNum = 0
				this.getInExamineProjectTree(val)
				this.getDicts("equip_main_status").then(response => {
					this.statusOptions = response.data.data;
				});
				this.getDicts("examine_status").then(response => {
					this.mainOptions = response.data.data;
				});
			},
			recording(ucId) {
				window.native.MaintenanceRecordVideo({
					ucId: ucId,
					maintenanceId: this.examineTaskInfo.ucId
				}, res => {
					this.getInExamineProjectTree(this.ucId)
				});
			},
			getInExamineProjectTree(val) {
				this.utils.request("/api/app/examine/getInExamineProjectTree", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.examineTaskInfo = res.data
					this.loading = false
				}).catch(error => {
					this.loading = false
					console.log(error)
				})
			},
			open() {
				this.$refs.popup.open('center')
			},
			close() {
				this.$refs.popup.close()
			},
			//开始任务
			startExecute() {
				this.utils.request("/api/app/examine/startExecute", {
					ucId: this.ucId,enterpriseId:this.examineTaskInfo.task.enterpriseId
				}, "get", "app", true).then(res => {
					this.initView(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			//重启/暂停执行
			setStartExamine() {
				this.utils.request("/api/app/examine/setStartExamine", {
					isStop: this.examineTaskInfo.task.isStop,ucId: this.ucId,
					enterpriseId:this.examineTaskInfo.task.enterpriseId
				}, "get", "app", true).then(res => {
					this.initView(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			//结束本次检测
			completeTask() {
				this.utils.request("/api/app/examine/completeTask", {
					ucId: this.ucId,
					enterpriseId:this.examineTaskInfo.task.enterpriseId
				}, "get", "app", true).then(res => {
					this.initView(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			reportHiddenDanger(mainDataId, equipmentId) {
				uni.navigateTo({
					url: '/pages/index/workorder/maintenance/maintenanceHiddenDanger?ucId=' + this.examineTaskInfo
						.ucId + "&equipmentId=" + equipmentId + "&mainDataId=" + mainDataId
				});
			},
			compileEq() {
				uni.navigateTo({
					url: '/pages/index/workorder/task/completeEqList?ucId=' + this.examineTaskInfo.enterpriseId
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/uview-ui/libs/css/style.components.scss";

	.list-item {
		padding: 20rpx 40rpx;
		background-color: #fff;
		border-bottom: #999999 1px dashed;

		.list-bottom {
			display: flex;
			margin-top: 10rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #333;
		}

		.list-center {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #999999;
		}
	}

	.collapse-title {
		padding: 0px 9px;
	}

	.uni-collapse-cell--open {
		background-color: #FFFFFF !important;
	}

	.topicon>>>.icon {
		border: #4CD964 2upx solid;
	}
</style>
